package 力扣日常刷题.木22二月.第09天215;

/**
 * @author 帅小伙
 * @date 2022/2/15
 * @description 后续遍历    小 大 中
 */
public class Demo61二叉搜索树的后序遍历序列 {

    public boolean verifyPostorder(int[] postorder) {
        return recur(postorder,0,postorder.length - 1);
    }

    public boolean recur(int[] postorder, int i, int j) {
        if (i >= j) return true;
        int p = i;
        while (postorder[p] < postorder[j]) p++;
        int m = p;
        while (postorder[p] > postorder[j]) p++;
        return p == j && recur(postorder, i, m - 1) && recur(postorder, m, j - 1);
    }


}
